package director;

import creational.prototype.BadClone;
import creational.prototype.DeepClone;
import creational.prototype.ShadowClone;

public class PrototypeDirector {

    public static void main(String[] args) {
        //shadow clone
        ShadowClone sc = new ShadowClone("test1");
        ShadowClone scClone = sc.clone();
        scClone.setName("test2");
        System.out.println("原来的名字："+sc.getName());
        System.out.println("clone对象的名字："+scClone.getName());
        //deep clone
        DeepClone dc = new DeepClone("dc1");
        System.out.println("深克隆前第一个元素："+dc.getChildList().get(0).getName());
        DeepClone dcClone = dc.clone();
        dcClone.getChildList().get(0).setName("999");
        System.out.println("深克隆后第一个元素："+dc.getChildList().get(0).getName());
        //bad clone
        BadClone bc = new BadClone("bc1");
        System.out.println("坏克隆前第一个元素："+bc.getChildList().get(0).getName());
        BadClone bcClone = bc.clone();
        bcClone.getChildList().get(0).setName("999");
        System.out.println("坏克隆后第一个元素："+bc.getChildList().get(0).getName());
    }
}
